﻿using IM.Easy.Core.Audit;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IM.Easy.Entity.Scheduled
{
    [SugarTable]
    public class JobExecutionHistory : Auditable
    {
        /// <summary>
        /// 作业执行历史记录唯一标识符
        /// </summary>
        [SugarColumn(IsPrimaryKey = true, ColumnDescription = "主键")]
        public Guid HistoryId { get; set; }

        /// <summary>
        /// 执行编码
        /// </summary>
        [SugarColumn(ColumnDescription = "执行编码", IsNullable = true)]
        public string FireInstanceId { get; set; }

        /// <summary>
        /// 关联作业的唯一标识符
        /// </summary>
        [SugarColumn(ColumnDescription = "作业标识")]
        public Guid JobId { get; set; }

        /// <summary>
        /// 关联触发器的唯一标识符
        /// </summary>
        [SugarColumn(ColumnDescription = "触发编码")]
        public Guid TriggerId { get; set; }

        /// <summary>
        /// 作业开始执行时间
        /// </summary>
        [SugarColumn(ColumnDescription = "执行时间")]
        public DateTime StartTime { get; set; }

        /// <summary>
        /// 作业结束执行时间，可为 null
        /// </summary>
        [SugarColumn(ColumnDescription = "结束时间")]
        public DateTime? EndTime { get; set; }

        /// <summary>
        /// 耗时（ms）
        /// </summary>
        [SugarColumn(ColumnDescription = "耗时（ms）")]
        public long Duration { get; set; }

        /// <summary>
        /// 作业执行结果状态，如成功、失败
        /// </summary>
        [SugarColumn(ColumnDescription = "作业结果")]
        public bool Success { get; set; }

        /// <summary>
        /// 作业执行错误信息，无错误则为 null
        /// </summary>
        [SugarColumn(ColumnDescription = "错误消息", ColumnDataType = StaticConfig.CodeFirst_BigString, IsNullable = true)]
        public string ErrorMessage { get; set; }

        /// <summary>
        /// 关联任务
        /// </summary>
        [Navigate(NavigateType.OneToOne, nameof(JobId))]
        public ScheduledJob Job { get; set; }

    }
}
